<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use Hyperf\Coroutine\Coroutine;
use xsl\basic\BaseController;

class IndexController extends BaseController
{
    public function index()
    {
        go(function () {
            $i = 0;
            while (true) {
                Coroutine::sleep(0.1);
                echo "📝  Do something...\n";
                if (++$i === 5) {
                    echo "🛎  Done\n";
                    break;
                }
            }
            echo "🎉  All right!\n";
        });

        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
